<?php

namespace App\Console\Commands;

use App\Models\ModelNumber;
use App\Models\Product;
use App\Models\ProductModelNumber;
use Illuminate\Console\Command;

class AddModelNumber extends Command
{
    /**
     * The name and signature of the console command.
     * php artisan command:addmodelnumber
     * @var string
     */
    protected $signature = 'command:addmodelnumber';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $arr = [
            'ruanchuang_arr' => [
                'level'=>4,
                'data'=>[
                '1206',
                '9083',
                '407',
                '1186',
                '1180',
                'A22-2',
                'D19-12',
                'E2305',
                'YC-134',
                'E22-16',
                'D23-09',
                'D20-2-1',
                '大象耳朵',
                '长灯款',
                'D23-02',
                'D23-01',
                'D20-23-1',
                'E22-15',
                '云朵床',
                '香奈儿',
                '434',
                '轻奢330',
                '轻奢618',
                '轻奢619',
                'D22-02'
            ]
            ],
            'shafa_arr' => [
                'level'=>1,
                'data'=>[
                    '6668',
                    '6660',
                    'MYJ-7',
                    'C9061',
                    'C9068',
                    '2238',
                    '8868',
                    '2268',
                    '2060',
                    '帆船前后推移',
                    '劳伦斯',
                    '8001',
                    '8175',
                    '2238',
                    '2014',
                    '2225',
                    '22--9',
                    'A815',
                    '2228',
                    '2248',
                    '2238',
                    '8603',
                    'F8612',
                    'F8605',
                    'F14-08',
                    '8615'
                ],
            ],
            'lachang_arr' => [
                'level'=>2,
                'data'=>[
                    'X22-9',
                    'X23-01',
                    'JY37',
                    'JY52',
                    'JY53'
                ]
            ],
            'chuangban_arr' => [
                'level'=>5,
                'data'=>[
                    '铁拍子',
                    '实木板',
                    '满铺板拍子',
                    '宽板拍子'
                ]
            ],
            'chuangbang_arr' => [
                'level'=>6,
                'data'=>[
                    'B气动',
                    'B无气动',
                    'A气动',
                    'A无气动',
                    '8厘米帮',
                    '12厘米帮',
                    '15厘米帮',
                    '18厘米帮',
                    '20厘米帮'
                ]
            ],
            'chuangtou_arr' => [
                'level'=>7,
                'data'=>[
                    '1206',
                    '9083',
                    '407',
                    '1186',
                    '1180',
                    'A22-2',
                    'D19-12',
                    'E2305',
                    'YC-134',
                    'E22-16',
                    'D23-09',
                    'D20-2-1',
                    '大象耳朵',
                    '长灯款',
                    'D23-02',
                    'D23-01',
                    'D20-23-1',
                    'E22-15',
                    '云朵床',
                    '香奈儿',
                    '434',
                    '轻奢330',
                    '轻奢618',
                    '轻奢619',
                    'D22-02',
                    'E19-04',
                    'D21-1',
                    'D20-2',
                    'E21-11',
                    '轻奢619',
                    'E19-04',
                    'D21-11',
                    'E21-06',
                    '203',
                    'E19-04双靠包',
                    '2883',
                    'E20-23',
                    'E2012',
                    '轻奢618',
                    'A071',
                    '139',
                    'D20-2-1',
                    '147',
                    'E19-02',
                    'D20-23-1',
                    'X-107',
                    '861-23',
                    'E20-23-1',
                    '轻奢330',
                    'D19-2',
                    '1998',
                    'E22-25',
                    'D23-06',
                    'D23-07',
                    'D23-02',
                    'D23-08',
                    'D23-09',
                    'D23-03'

                ]
            ],
        ];

        foreach($arr as $k=>$v){
            $product = Product::where('is_del',2)->where('able_level',$v['level'])->get()->toArray();
            foreach ($product as $kk=>$vv){
                foreach($v['data'] as $kkk=>$vvv){
                    $model_number_obj = ModelNumber::updateOrCreate(
                        [
                            'model_number'=>$vvv
                        ],[
                            'model_number'=>$vvv,'is_del'=>2
                        ]
                    );
                    ProductModelNumber::updateOrCreate(
                        [
                            'product_id'=>$vv['id'],'model_number_id'=>$model_number_obj->id
                        ],[
                            'product_id'=>$vv['id'],'model_number_id'=>$model_number_obj->id
                        ]
                    );
                    $this->info('产品：'.$vv['product_name'].";型号：".$vvv);
                }
            }
        }

    }
}
